/*
 * @Author: coderzi
 * @Description:主播福利
 */
import { Component, OnInit, Input } from '@angular/core';
import { UserService } from 'src/app/service/user.service';
import { YearawardService } from '../../yearaward.service';
import { BaseService } from 'src/app/service/base.service';
import { UtilsService } from 'src/app/service/utils.service';
import { WELFARE_ANCHOR_MAP } from '../index.map';
import type { Subscription } from 'rxjs';

@Component({
  selector: 'app-welfare-anchor',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.scss'],
})
export class WelfareAnchorComponent implements OnInit {
  @Input() timeConfig: any[] = [];
  /* ___ _ ___ */
  public deployUrl: string; /* 资源地址前缀 */
  private reshing: Subscription = null; /* 订阅刷新 */
  public readonly layoutMap = WELFARE_ANCHOR_MAP;
  /* ___ _ ___ */
  public isPC = false; /* 是否pc */
  public isAndroid = false; /* 是否安卓 */
  public onRefrash = false; /* 刷新中 */
  /* ___ _ ___ */
  public score: number = 0; /* 主播贡献积分 */

  constructor(
    private userService: UserService,
    private yearawardService: YearawardService,
    private baseService: BaseService,
    private utilsService: UtilsService
  ) {}

  ngOnInit(): void {
    // 获取
    this.deployUrl = this.userService.getDeployUrl();
    this.isPC = this.userService.getIsPc();
    this.isAndroid = this.utilsService.getBrowserVersion();
    // 请求数据
    this.getScore();

    // 组件刷新通信
    this.reshing = this.utilsService.MsgSub.subscribe((res: any) => {
      this.getScore();
    });
  }

  ngOnDestroy(): void {
    /* 取消订阅 */
    if (this.reshing) this.reshing.unsubscribe();
  }

  /**
   * @description: 获取贡献积分
   */
  getScore() {
    this.yearawardService.getAnchorUserScore(
      (res) => {
        this.score = res.data.score;
        console.log('获取贡献积分=>', res.data.score);
      },
      () => {},
      0
    );
  }
}
